#!/bin/bash

# Source global definitions
if [ -f /etc/bashrc ]; then
	. /etc/bashrc
fi

module use /home/software/rhel/8/modulefiles

install_ident=gcc850_omp4_ucx
install_ident_ESMF=gcc850_omp4_ucx_hybrid

module add gcc/8.5.0
module add openmpi/4.1.4_testing
module add netcdf/4_testing hdf5/1.12.2_testing


export FC=gfortran
export F77=$FC
export F90=$FC
export F9X=$FC
export CC=gcc
export CXX=g++
export CPP=cpp

export OMPI_CC=$CC
export OMPI_CXX=$CXX

# Add OpenMPI
export MPI_ROOT=$( dirname $( dirname $( which mpirun ) ) )

export NETCDF_HOME=$( dirname $( dirname $( which nc-config ) ) )
export NETCDF_FORTRAN_HOME=/home/seastham/local_${install_ident}
export PATH=$NETCDF_FORTRAN_HOME/bin:${PATH}

if [[ ! -e $MPI_ROOT/bin/mpicc ]]; then
    echo "mpicc not found; reverting to serial compilers"
else
    export FC=mpif90
    export CC=mpicc
    export CXX=mpicxx
    export F77=$FC
    export F90=$FC
    export F9X=$FC
fi

export ESMF_COMM=openmpi
export ESMF_COMPILER=gfortran
export ESMF_DIR=/home/seastham/ESMF/ESMF_v800
export ESMF_INSTALL_PREFIX=${ESMF_DIR}/INSTALL_${install_ident_ESMF}
export ESMF_ROOT=${ESMF_INSTALL_PREFIX}
export ESMF_OPENMP=ON
export ESMF_NETCDF=nc-config

ulimit -l unlimited
ulimit -s unlimited
ulimit -c 0
export KMP_STACKSIZE=100000000
if [[ -z $SLURM_CPUS_PER_TASK ]]; then
    export OMP_NUM_THREADS=1
else
    export OMP_NUM_THREADS=$SLURM_CPUS_PER_TASK
fi

unset PROMPT_COMMAND
